package b.k.a;

import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.OverScroller;
import b.i.k.o;
import java.util.Arrays;
import java.util.Objects;

/* compiled from: ViewDragHelper */
public class e {
    public static final Interpolator v = new a();
    public int a;
    public int b;
    public int c = -1;
    public float[] d;
    public float[] e;
    public float[] f;
    public float[] g;
    public int[] h;
    public int[] i;
    public int[] j;
    public int k;
    public VelocityTracker l;
    public float m;
    public float n;
    public int o;
    public OverScroller p;
    public final c q;
    public View r;
    public boolean s;
    public final ViewGroup t;
    public final Runnable u = new b();

    /* compiled from: ViewDragHelper */
    public static class a implements Interpolator {
        public float getInterpolation(float f) {
            f -= 1.0f;
            return ((((f * f) * f) * f) * f) + 1.0f;
        }
    }

    /* compiled from: ViewDragHelper */
    public class b implements Runnable {
        public void run() {
            e.this.s(0);
        }
    }

    /* compiled from: ViewDragHelper */
    public static abstract class c {
        public abstract int a(View view, int i, int i2);

        public abstract int b(View view, int i, int i2);

        public int c(View view) {
            return 0;
        }

        public int d(View view) {
            return 0;
        }

        public void e(View view, int i) {
        }

        public abstract void f(int i);

        public abstract void g(View view, int i, int i2, int i3, int i4);

        public abstract void h(View view, float f, float f2);

        public abstract boolean i(View view, int i);
    }

    public e(Context context, ViewGroup viewGroup, c cVar) {
        if (cVar != null) {
            this.t = viewGroup;
            this.q = cVar;
            ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
            this.o = (int) ((context.getResources().getDisplayMetrics().density * 20.0f) + 0.5f);
            this.b = viewConfiguration.getScaledTouchSlop();
            this.m = (float) viewConfiguration.getScaledMaximumFlingVelocity();
            this.n = (float) viewConfiguration.getScaledMinimumFlingVelocity();
            this.p = new OverScroller(context, v);
            return;
        }
        throw new IllegalArgumentException("Callback may not be null");
    }

    public void a() {
        this.c = -1;
        float[] fArr = this.d;
        if (fArr != null) {
            Arrays.fill(fArr, 0.0f);
            Arrays.fill(this.e, 0.0f);
            Arrays.fill(this.f, 0.0f);
            Arrays.fill(this.g, 0.0f);
            Arrays.fill(this.h, 0);
            Arrays.fill(this.i, 0);
            Arrays.fill(this.j, 0);
            this.k = 0;
        }
        VelocityTracker velocityTracker = this.l;
        if (velocityTracker != null) {
            velocityTracker.recycle();
            this.l = null;
        }
    }

    public void b(View view, int i) {
        if (view.getParent() == this.t) {
            this.r = view;
            this.c = i;
            this.q.e(view, i);
            s(1);
            return;
        }
        StringBuilder g = c.b.a.a.a.g("captureChildView: parameter must be a descendant of the ViewDragHelper's tracked parent view (");
        g.append(this.t);
        g.append(")");
        throw new IllegalArgumentException(g.toString());
    }

    public final boolean c(float f, float f2, int i, int i2) {
        f = Math.abs(f);
        f2 = Math.abs(f2);
        if ((this.h[i] & i2) != i2 || (0 & i2) == 0 || (this.j[i] & i2) == i2 || (this.i[i] & i2) == i2) {
            return false;
        }
        int i3 = this.b;
        if (f <= ((float) i3) && f2 <= ((float) i3)) {
            return false;
        }
        if (f < f2 * 0.5f) {
            Objects.requireNonNull(this.q);
        }
        if ((this.i[i] & i2) != 0 || f <= ((float) this.b)) {
            return false;
        }
        return true;
    }

    public final boolean d(View view, float f, float f2) {
        boolean z = false;
        if (view == null) {
            return false;
        }
        Object obj = this.q.c(view) > 0 ? 1 : null;
        Object obj2 = this.q.d(view) > 0 ? 1 : null;
        if (obj != null && obj2 != null) {
            f2 = (f2 * f2) + (f * f);
            int i = this.b;
            if (f2 > ((float) (i * i))) {
                z = true;
            }
            return z;
        } else if (obj != null) {
            if (Math.abs(f) > ((float) this.b)) {
                z = true;
            }
            return z;
        } else {
            if (obj2 != null && Math.abs(f2) > ((float) this.b)) {
                z = true;
            }
            return z;
        }
    }

    public final float e(float f, float f2, float f3) {
        float abs = Math.abs(f);
        if (abs < f2) {
            return 0.0f;
        }
        if (abs <= f3) {
            return f;
        }
        if (f <= 0.0f) {
            f3 = -f3;
        }
        return f3;
    }

    public final int f(int i, int i2, int i3) {
        int abs = Math.abs(i);
        if (abs < i2) {
            return 0;
        }
        if (abs <= i3) {
            return i;
        }
        if (i <= 0) {
            i3 = -i3;
        }
        return i3;
    }

    public final void g(int i) {
        float[] fArr = this.d;
        if (fArr != null) {
            int i2 = this.k;
            int i3 = 1;
            int i4 = 1 << i;
            if ((i4 & i2) == 0) {
                i3 = 0;
            }
            if (i3 != 0) {
                fArr[i] = 0.0f;
                this.e[i] = 0.0f;
                this.f[i] = 0.0f;
                this.g[i] = 0.0f;
                this.h[i] = 0;
                this.i[i] = 0;
                this.j[i] = 0;
                this.k = (~i4) & i2;
            }
        }
    }

    public final int h(int i, int i2, int i3) {
        if (i == 0) {
            return 0;
        }
        int width = this.t.getWidth();
        float f = (float) (width / 2);
        float sin = (((float) Math.sin((double) ((Math.min(1.0f, ((float) Math.abs(i)) / ((float) width)) - 0.5f) * 0.47123894f))) * f) + f;
        i2 = Math.abs(i2);
        if (i2 > 0) {
            i = Math.round(Math.abs(sin / ((float) i2)) * 1000.0f) * 4;
        } else {
            i = (int) (((((float) Math.abs(i)) / ((float) i3)) + 1.0f) * 256.0f);
        }
        return Math.min(i, 600);
    }

    public boolean i(boolean z) {
        if (this.a == 2) {
            boolean computeScrollOffset = this.p.computeScrollOffset();
            int currX = this.p.getCurrX();
            int currY = this.p.getCurrY();
            int left = currX - this.r.getLeft();
            int top = currY - this.r.getTop();
            if (left != 0) {
                o.j(this.r, left);
            }
            if (top != 0) {
                o.k(this.r, top);
            }
            if (!(left == 0 && top == 0)) {
                this.q.g(this.r, currX, currY, left, top);
            }
            if (computeScrollOffset && currX == this.p.getFinalX() && currY == this.p.getFinalY()) {
                this.p.abortAnimation();
                computeScrollOffset = false;
            }
            if (!computeScrollOffset) {
                if (z) {
                    this.t.post(this.u);
                } else {
                    s(0);
                }
            }
        }
        if (this.a == 2) {
            return true;
        }
        return false;
    }

    public final void j(float f, float f2) {
        this.s = true;
        this.q.h(this.r, f, f2);
        this.s = false;
        if (this.a == 1) {
            s(0);
        }
    }

    public View k(int i, int i2) {
        for (int childCount = this.t.getChildCount() - 1; childCount >= 0; childCount--) {
            ViewGroup viewGroup = this.t;
            Objects.requireNonNull(this.q);
            View childAt = viewGroup.getChildAt(childCount);
            if (i >= childAt.getLeft() && i < childAt.getRight() && i2 >= childAt.getTop() && i2 < childAt.getBottom()) {
                return childAt;
            }
        }
        return null;
    }

    public final boolean l(int i, int i2, int i3, int i4) {
        int left = this.r.getLeft();
        int top = this.r.getTop();
        int i5 = i - left;
        int i6 = i2 - top;
        if (i5 == 0 && i6 == 0) {
            this.p.abortAnimation();
            s(0);
            return false;
        }
        float f;
        float f2;
        float f3;
        View view = this.r;
        i2 = f(i3, (int) this.n, (int) this.m);
        i3 = f(i4, (int) this.n, (int) this.m);
        i4 = Math.abs(i5);
        int abs = Math.abs(i6);
        int abs2 = Math.abs(i2);
        int abs3 = Math.abs(i3);
        int i7 = abs2 + abs3;
        int i8 = i4 + abs;
        if (i2 != 0) {
            f = (float) abs2;
            f2 = (float) i7;
        } else {
            f = (float) i4;
            f2 = (float) i8;
        }
        f /= f2;
        if (i3 != 0) {
            f3 = (float) abs3;
            f2 = (float) i7;
        } else {
            f3 = (float) abs;
            f2 = (float) i8;
        }
        f3 /= f2;
        i2 = h(i5, i2, this.q.c(view));
        this.p.startScroll(left, top, i5, i6, (int) ((((float) h(i6, i3, this.q.d(view))) * f3) + (((float) i2) * f)));
        s(2);
        return true;
    }

    public final boolean m(int i) {
        if (((this.k & (1 << i)) != 0 ? 1 : null) != null) {
            return true;
        }
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("Ignoring pointerId=");
        stringBuilder.append(i);
        stringBuilder.append(" because ACTION_DOWN was not received ");
        stringBuilder.append("for this pointer before ACTION_MOVE. It likely happened because ");
        stringBuilder.append(" ViewDragHelper did not receive all the events in the event stream.");
        Log.e("ViewDragHelper", stringBuilder.toString());
        return false;
    }

    public void n(MotionEvent motionEvent) {
        int actionMasked = motionEvent.getActionMasked();
        int actionIndex = motionEvent.getActionIndex();
        if (actionMasked == 0) {
            a();
        }
        if (this.l == null) {
            this.l = VelocityTracker.obtain();
        }
        this.l.addMovement(motionEvent);
        int i = 0;
        float x;
        float y;
        int pointerId;
        float x2;
        View view;
        int pointerId2;
        if (actionMasked == 0) {
            x = motionEvent.getX();
            y = motionEvent.getY();
            pointerId = motionEvent.getPointerId(0);
            View k = k((int) x, (int) y);
            q(x, y, pointerId);
            v(k, pointerId);
            if ((this.h[pointerId] & 0) != 0) {
                Objects.requireNonNull(this.q);
            }
        } else if (actionMasked == 1) {
            if (this.a == 1) {
                o();
            }
            a();
        } else if (actionMasked != 2) {
            if (actionMasked == 3) {
                if (this.a == 1) {
                    j(0.0f, 0.0f);
                }
                a();
            } else if (actionMasked == 5) {
                actionMasked = motionEvent.getPointerId(actionIndex);
                x2 = motionEvent.getX(actionIndex);
                float y2 = motionEvent.getY(actionIndex);
                q(x2, y2, actionMasked);
                if (this.a == 0) {
                    v(k((int) x2, (int) y2), actionMasked);
                    if ((this.h[actionMasked] & 0) != 0) {
                        Objects.requireNonNull(this.q);
                        return;
                    }
                    return;
                }
                actionIndex = (int) x2;
                pointerId = (int) y2;
                view = this.r;
                if (view != null && actionIndex >= view.getLeft() && actionIndex < view.getRight() && pointerId >= view.getTop() && pointerId < view.getBottom()) {
                    i = 1;
                }
                if (i != 0) {
                    v(this.r, actionMasked);
                }
            } else if (actionMasked == 6) {
                actionMasked = motionEvent.getPointerId(actionIndex);
                if (this.a == 1 && actionMasked == this.c) {
                    actionIndex = motionEvent.getPointerCount();
                    while (i < actionIndex) {
                        pointerId2 = motionEvent.getPointerId(i);
                        if (pointerId2 != this.c) {
                            View k2 = k((int) motionEvent.getX(i), (int) motionEvent.getY(i));
                            View view2 = this.r;
                            if (k2 == view2 && v(view2, pointerId2)) {
                                pointerId = this.c;
                                break;
                            }
                        }
                        i++;
                    }
                    pointerId = -1;
                    if (pointerId == -1) {
                        o();
                    }
                }
                g(actionMasked);
            }
        } else if (this.a != 1) {
            actionMasked = motionEvent.getPointerCount();
            while (i < actionMasked) {
                actionIndex = motionEvent.getPointerId(i);
                if (m(actionIndex)) {
                    x2 = motionEvent.getX(i);
                    float y3 = motionEvent.getY(i);
                    float f = x2 - this.d[actionIndex];
                    float f2 = y3 - this.e[actionIndex];
                    p(f, f2, actionIndex);
                    if (this.a != 1) {
                        view = k((int) x2, (int) y3);
                        if (d(view, f, f2) && v(view, actionIndex)) {
                            break;
                        }
                    }
                    break;
                }
                i++;
            }
            r(motionEvent);
        } else if (m(this.c)) {
            actionMasked = motionEvent.findPointerIndex(this.c);
            y = motionEvent.getX(actionMasked);
            x = motionEvent.getY(actionMasked);
            float[] fArr = this.f;
            int i2 = this.c;
            actionIndex = (int) (y - fArr[i2]);
            actionMasked = (int) (x - this.g[i2]);
            i = this.r.getLeft() + actionIndex;
            i2 = this.r.getTop() + actionMasked;
            pointerId2 = this.r.getLeft();
            int top = this.r.getTop();
            if (actionIndex != 0) {
                i = this.q.a(this.r, i, actionIndex);
                o.j(this.r, i - pointerId2);
            }
            int i3 = i;
            if (actionMasked != 0) {
                i2 = this.q.b(this.r, i2, actionMasked);
                o.k(this.r, i2 - top);
            }
            int i4 = i2;
            if (!(actionIndex == 0 && actionMasked == 0)) {
                this.q.g(this.r, i3, i4, i3 - pointerId2, i4 - top);
            }
            r(motionEvent);
        }
    }

    public final void o() {
        this.l.computeCurrentVelocity(1000, this.m);
        j(e(this.l.getXVelocity(this.c), this.n, this.m), e(this.l.getYVelocity(this.c), this.n, this.m));
    }

    public final void p(float f, float f2, int i) {
        int i2 = 1;
        if (!c(f, f2, i, 1)) {
            i2 = 0;
        }
        if (c(f2, f, i, 4)) {
            i2 |= 4;
        }
        if (c(f, f2, i, 2)) {
            i2 |= 2;
        }
        if (c(f2, f, i, 8)) {
            i2 |= 8;
        }
        if (i2 != 0) {
            int[] iArr = this.i;
            iArr[i] = iArr[i] | i2;
            Objects.requireNonNull(this.q);
        }
    }

    public final void q(float f, float f2, int i) {
        int[] iArr;
        float[] fArr = this.d;
        int i2 = 0;
        if (fArr == null || fArr.length <= i) {
            int i3 = i + 1;
            float[] fArr2 = new float[i3];
            float[] fArr3 = new float[i3];
            float[] fArr4 = new float[i3];
            float[] fArr5 = new float[i3];
            int[] iArr2 = new int[i3];
            int[] iArr3 = new int[i3];
            int[] iArr4 = new int[i3];
            if (fArr != null) {
                System.arraycopy(fArr, 0, fArr2, 0, fArr.length);
                fArr = this.e;
                System.arraycopy(fArr, 0, fArr3, 0, fArr.length);
                fArr = this.f;
                System.arraycopy(fArr, 0, fArr4, 0, fArr.length);
                fArr = this.g;
                System.arraycopy(fArr, 0, fArr5, 0, fArr.length);
                iArr = this.h;
                System.arraycopy(iArr, 0, iArr2, 0, iArr.length);
                iArr = this.i;
                System.arraycopy(iArr, 0, iArr3, 0, iArr.length);
                iArr = this.j;
                System.arraycopy(iArr, 0, iArr4, 0, iArr.length);
            }
            this.d = fArr2;
            this.e = fArr3;
            this.f = fArr4;
            this.g = fArr5;
            this.h = iArr2;
            this.i = iArr3;
            this.j = iArr4;
        }
        fArr = this.d;
        this.f[i] = f;
        fArr[i] = f;
        fArr = this.e;
        this.g[i] = f2;
        fArr[i] = f2;
        iArr = this.h;
        int i4 = (int) f;
        int i5 = (int) f2;
        if (i4 < this.t.getLeft() + this.o) {
            i2 = 1;
        }
        if (i5 < this.t.getTop() + this.o) {
            i2 |= 4;
        }
        if (i4 > this.t.getRight() - this.o) {
            i2 |= 2;
        }
        if (i5 > this.t.getBottom() - this.o) {
            i2 |= 8;
        }
        iArr[i] = i2;
        this.k |= 1 << i;
    }

    public final void r(MotionEvent motionEvent) {
        int pointerCount = motionEvent.getPointerCount();
        for (int i = 0; i < pointerCount; i++) {
            int pointerId = motionEvent.getPointerId(i);
            if (m(pointerId)) {
                float x = motionEvent.getX(i);
                float y = motionEvent.getY(i);
                this.f[pointerId] = x;
                this.g[pointerId] = y;
            }
        }
    }

    public void s(int i) {
        this.t.removeCallbacks(this.u);
        if (this.a != i) {
            this.a = i;
            this.q.f(i);
            if (this.a == 0) {
                this.r = null;
            }
        }
    }

    public boolean t(int i, int i2) {
        if (this.s) {
            return l(i, i2, (int) this.l.getXVelocity(this.c), (int) this.l.getYVelocity(this.c));
        }
        throw new IllegalStateException("Cannot settleCapturedViewAt outside of a call to Callback#onViewReleased");
    }

    /* JADX WARNING: Missing block: B:44:0x00dd, code skipped:
            if (r12 != r11) goto L_0x00e6;
     */
    public boolean u(android.view.MotionEvent r17) {
        /*
        r16 = this;
        r0 = r16;
        r1 = r17;
        r2 = r17.getActionMasked();
        r3 = r17.getActionIndex();
        if (r2 != 0) goto L_0x0011;
    L_0x000e:
        r16.a();
    L_0x0011:
        r4 = r0.l;
        if (r4 != 0) goto L_0x001b;
    L_0x0015:
        r4 = android.view.VelocityTracker.obtain();
        r0.l = r4;
    L_0x001b:
        r4 = r0.l;
        r4.addMovement(r1);
        r4 = 2;
        r5 = 1;
        r6 = 0;
        if (r2 == 0) goto L_0x0104;
    L_0x0025:
        if (r2 == r5) goto L_0x00ff;
    L_0x0027:
        if (r2 == r4) goto L_0x006f;
    L_0x0029:
        r7 = 3;
        if (r2 == r7) goto L_0x00ff;
    L_0x002c:
        r7 = 5;
        if (r2 == r7) goto L_0x003d;
    L_0x002f:
        r4 = 6;
        if (r2 == r4) goto L_0x0034;
    L_0x0032:
        goto L_0x0102;
    L_0x0034:
        r1 = r1.getPointerId(r3);
        r0.g(r1);
        goto L_0x0102;
    L_0x003d:
        r2 = r1.getPointerId(r3);
        r7 = r1.getX(r3);
        r1 = r1.getY(r3);
        r0.q(r7, r1, r2);
        r3 = r0.a;
        if (r3 != 0) goto L_0x005e;
    L_0x0050:
        r1 = r0.h;
        r1 = r1[r2];
        r1 = r1 & r6;
        if (r1 == 0) goto L_0x0102;
    L_0x0057:
        r1 = r0.q;
        java.util.Objects.requireNonNull(r1);
        goto L_0x0102;
    L_0x005e:
        if (r3 != r4) goto L_0x0102;
    L_0x0060:
        r3 = (int) r7;
        r1 = (int) r1;
        r1 = r0.k(r3, r1);
        r3 = r0.r;
        if (r1 != r3) goto L_0x0102;
    L_0x006a:
        r0.v(r1, r2);
        goto L_0x0102;
    L_0x006f:
        r2 = r0.d;
        if (r2 == 0) goto L_0x0102;
    L_0x0073:
        r2 = r0.e;
        if (r2 != 0) goto L_0x0079;
    L_0x0077:
        goto L_0x0102;
    L_0x0079:
        r2 = r17.getPointerCount();
        r3 = 0;
    L_0x007e:
        if (r3 >= r2) goto L_0x00fb;
    L_0x0080:
        r4 = r1.getPointerId(r3);
        r7 = r0.m(r4);
        if (r7 != 0) goto L_0x008c;
    L_0x008a:
        goto L_0x00f7;
    L_0x008c:
        r7 = r1.getX(r3);
        r8 = r1.getY(r3);
        r9 = r0.d;
        r9 = r9[r4];
        r9 = r7 - r9;
        r10 = r0.e;
        r10 = r10[r4];
        r10 = r8 - r10;
        r7 = (int) r7;
        r8 = (int) r8;
        r7 = r0.k(r7, r8);
        if (r7 == 0) goto L_0x00b0;
    L_0x00a8:
        r8 = r0.d(r7, r9, r10);
        if (r8 == 0) goto L_0x00b0;
    L_0x00ae:
        r8 = 1;
        goto L_0x00b1;
    L_0x00b0:
        r8 = 0;
    L_0x00b1:
        if (r8 == 0) goto L_0x00e6;
    L_0x00b3:
        r11 = r7.getLeft();
        r12 = (int) r9;
        r13 = r11 + r12;
        r14 = r0.q;
        r12 = r14.a(r7, r13, r12);
        r13 = r7.getTop();
        r14 = (int) r10;
        r15 = r13 + r14;
        r6 = r0.q;
        r6 = r6.b(r7, r15, r14);
        r14 = r0.q;
        r14 = r14.c(r7);
        r15 = r0.q;
        r15 = r15.d(r7);
        if (r14 == 0) goto L_0x00df;
    L_0x00db:
        if (r14 <= 0) goto L_0x00e6;
    L_0x00dd:
        if (r12 != r11) goto L_0x00e6;
    L_0x00df:
        if (r15 == 0) goto L_0x00fb;
    L_0x00e1:
        if (r15 <= 0) goto L_0x00e6;
    L_0x00e3:
        if (r6 != r13) goto L_0x00e6;
    L_0x00e5:
        goto L_0x00fb;
    L_0x00e6:
        r0.p(r9, r10, r4);
        r6 = r0.a;
        if (r6 != r5) goto L_0x00ee;
    L_0x00ed:
        goto L_0x00fb;
    L_0x00ee:
        if (r8 == 0) goto L_0x00f7;
    L_0x00f0:
        r4 = r0.v(r7, r4);
        if (r4 == 0) goto L_0x00f7;
    L_0x00f6:
        goto L_0x00fb;
    L_0x00f7:
        r3 = r3 + 1;
        r6 = 0;
        goto L_0x007e;
    L_0x00fb:
        r16.r(r17);
        goto L_0x0102;
    L_0x00ff:
        r16.a();
    L_0x0102:
        r2 = 0;
        goto L_0x0132;
    L_0x0104:
        r2 = r17.getX();
        r3 = r17.getY();
        r6 = 0;
        r1 = r1.getPointerId(r6);
        r0.q(r2, r3, r1);
        r2 = (int) r2;
        r3 = (int) r3;
        r2 = r0.k(r2, r3);
        r3 = r0.r;
        if (r2 != r3) goto L_0x0125;
    L_0x011e:
        r3 = r0.a;
        if (r3 != r4) goto L_0x0125;
    L_0x0122:
        r0.v(r2, r1);
    L_0x0125:
        r2 = r0.h;
        r1 = r2[r1];
        r2 = 0;
        r1 = r1 & r2;
        if (r1 == 0) goto L_0x0132;
    L_0x012d:
        r1 = r0.q;
        java.util.Objects.requireNonNull(r1);
    L_0x0132:
        r1 = r0.a;
        if (r1 != r5) goto L_0x0137;
    L_0x0136:
        goto L_0x0138;
    L_0x0137:
        r5 = 0;
    L_0x0138:
        return r5;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.k.a.e.u(android.view.MotionEvent):boolean");
    }

    public boolean v(View view, int i) {
        if (view == this.r && this.c == i) {
            return true;
        }
        if (view == null || !this.q.i(view, i)) {
            return false;
        }
        this.c = i;
        b(view, i);
        return true;
    }
}
